package xframe.util.mail;

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailSender
{

    public MailSender()
    {
        message_recip = "akami.kang@samsung.com";
        message_subject = "메일테스트";
        message_cc = "";
        message_body = "메일을 테스트 합니다.";
    }

    public void doSend()
    {
        Properties props = new Properties();
        props.put("mail.smtp.host", "118.220.172.71");
        session = Session.getDefaultInstance(props, null);
        session.setDebug(true);
        try
        {
            msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("akami.kang@samsung.com"));
            InternetAddress toAddress = new InternetAddress(message_recip);
            msg.addRecipient(javax.mail.Message.RecipientType.TO, toAddress);
            InternetAddress ccAddress = new InternetAddress(message_recip);
            msg.addRecipient(javax.mail.Message.RecipientType.CC, ccAddress);
            msg.setSubject(message_subject);
            msg.setText(message_body);
            Transport.send(msg);
        }
        catch(MessagingException e)
        {
            while((e = (MessagingException)e.getNextException()) != null) 
                e.printStackTrace();
        }
    }

    public static void main(String args[])
    {
        MailSender sm = new MailSender();
        sm.doSend();
    }

    protected String message_recip;
    protected String message_subject;
    protected String message_cc;
    protected String message_body;
    protected Session session;
    protected Message msg;
}
